﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using School.Entities;

namespace School.Service.BOOKS
{
    public class SRV_BOOK_Price
    {
        private static SchoolEntities db = new SchoolEntities();
        public static IEnumerable<object> BookPrice(long campsId,long CerId,long Grade,long Stage)
        {
            var query = from book in db.SRV_Book
                        where book.Campus_Id == campsId && book.Cer_Id == CerId && book.Grad_Id == Grade &&
                        book.Stage_Id == Stage
                        select new
                        {
                            book_Id = book.Id,
                            Code = book.Code,
                            Descrption = book.Description,
                            BookName = book.Name,
                            Price = (double?)db.SRV_Book_Price.OrderByDescending(s => s.Price_Id).Where(s=>s.Book_Id == book.Id).FirstOrDefault().Price
                        };
            return query;
        }
        public static bool PriceInsert(List<SRV_Book_Price> lstPrices)
        {
            foreach (SRV_Book_Price item in lstPrices)
            {
                db.AddToSRV_Book_Price(item);
            }
            try
            {
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    
    }
}
